package org.jeecg.websocket;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/socket")
@Slf4j
public class SendController {
    /**
     *
     * @param userId
     * @param event
     *   请避开以下内部event
     *             'connect',
     *             'error',
     *             'disconnect',
     *             'reconnect',
     *             'reconnect_attempt',
     *             'reconnecting',
     *             'reconnect_error',
     *             'reconnect_failed',
     *             'connect_error',
     *             'connect_timeout',
     *             'connecting',
     *             'ping',
     *             'pong'
     * @param res
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/send/{userId}/{event}", method = RequestMethod.POST)
    public String send(@PathVariable("userId") String userId, @PathVariable("event") String event, @RequestBody String res) throws Exception {
        // 返回值不是json, 而是成功发送给客户端的设备数量
        return ""+socketIOService.pushMessageToUser(userId,event, res);
    }

    @Autowired
    SocketIOService socketIOService;
}
